import { ref } from 'vue'
import { defineStore } from 'pinia'
import { useCommonStore } from '@/stores'

export const useUserStore = defineStore(
  'user',
  () => {
    // 用户信息
    const userInfo = ref({
      id: '',
      phone_number: '',
      user_token: '',
    })

    // 设置用户信息
    const setUserInfo = (info) => {
      userInfo.value = info
    }

    // 退出登录
    const resetUserInfo = () => {
      const { resetCommon } = useCommonStore()
      userInfo.value = {
        id: '',
        phone_number: '',
        user_token: '',
      }
      resetCommon()
    }

    return {
      userInfo,
      setUserInfo,
      resetUserInfo,
    }
  },
  {
    persist: true,
  },
)
